package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-03-25
 * Time: 9:55
 */
class OutClass {
    public int date = 10;
    private int date2 = 20;
    public static int date3 = 30;
    class InnerClass {//实例内部类
        public int date = 101;
        public int date4 = 40;
        private int date5 = 50;
        public static final int date6 = 30;
        public void  testInner() {
            System.out.println("alla");
            System.out.println(date);
            System.out.println(OutClass.this.date);//实例内部类存在外部类的this
            System.out.println(date2);
            System.out.println(date3);
            System.out.println(date4);
            System.out.println(date5);
            System.out.println(date6);
        }
    }
    public void test() {
        InnerClass innerClass = new InnerClass();
        System.out.println(innerClass.date5);
    }
}
class OutClass2 {
    public int date = 10;
    private int date2 = 20;
    public static int date3 = 30;
    //1.如何实例化静态内部类
    //2.如何访问外部类非静态成员
    static class InnerClass {//静态内部类
        public int date4 = 40;
        private int date5 = 50;
        public static int date6 = 30;
        public void testInner() {
            System.out.println("testInner");
            OutClass2 outClass2 = new OutClass2();//外部类对象
            System.out.println(outClass2.date);//外部类对象.
            System.out.println(outClass2.date2);
            System.out.println(date3);
            System.out.println(date4);
            System.out.println(date5);
            System.out.println(date6);
        }
    }
}
class Student implements Comparable<Student> {
    @Override
    public int compareTo(Student o) {
        return 0;
    }
}
interface Shape{
    void draw();
}
public class Test {
    public static void main(String[] args) {
        Comparable<Student> comparable = new Student();
        new Comparable<Student>() {
            @Override
            public int compareTo(Student o) {
                return 0;
            }
        };
        int a = 10;
        new Shape(){//匿名内部类
            @Override
            public void draw() {
                //a= 99;//在匿名内部类中，访问的变量是不能改变的
                System.out.println("juxing" + a);
            }
        }.draw();
        System.out.println("===================");
    }
    public static void main2(String[] args) {
        OutClass2.InnerClass innerClass = new OutClass2.InnerClass();//不需要外部类的对象就能实例化
        innerClass.testInner();
    }
    public static void main1(String[] args) {
        OutClass outClass = new OutClass();
        OutClass.InnerClass innerClass = outClass.new InnerClass();
        OutClass.InnerClass innerClass2 = new OutClass().new InnerClass();
        innerClass2.testInner();
        outClass.test();
    }
}
